package com.itheima.wisdomnext.service.ImpI;

import com.itheima.wisdomnext.entity.Report;
import com.itheima.wisdomnext.entity.ReportReason;
import com.itheima.wisdomnext.entity.Result.enumcalss.ErrorCode;
import com.itheima.wisdomnext.mapper.ReportMapper;
import com.itheima.wisdomnext.service.ReportService;
import com.itheima.wisdomnext.util.ReportS_Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    private ReportMapper reportMapper;

    @Override
    public void addReport(Report report) throws Exception{
        reportMapper.insertReport(report);
    }

    @Override
    public List<Report> getAllReports() {
        List<Report> allReports = reportMapper.findAllReports();
        if(allReports.size()<=0){
            ReportS_Util.isTrue(true, ErrorCode.FAILED,"获取的举报记录为空");
        }
        return allReports;
    }

    @Override
    public List<Report> getReportsByUserId(Integer reporterId) {
        List<Report> reportsByUserId = reportMapper.findReportsByUserId(reporterId);
        if(reportsByUserId.size()<=0){
            ReportS_Util.isTrue(true, ErrorCode.FAILED,"获取的举报记录为空");
        }
        return reportsByUserId;
    }

    @Override
    // 获取所有举报理由类型
    public List<ReportReason> getAllReportReasons() {
        List<ReportReason> reportreasons = reportMapper.Reportreasons();
        if(reportreasons.size()<=0){
            ReportS_Util.isTrue(true, ErrorCode.FAILED,"获取举报理由类型为空");
        }
        return reportreasons;
    }
}
